#ifndef PURPLE_PLUGINS
# define PURPLE_PLUGINS
#endif

#include "gtkplugin.h"
#include "config.h"
#include "prpl.h"
#include "version.h"
#include "xmlnode.h"

#include "pidgindbus.h"

static gboolean
plugin_load(PurplePlugin *plugin)
{
	PurplePlugin *jabber;
	PurplePlugin *handle;
	PurplePlugin *ft_handle;

	jabber = purple_find_prpl("prpl-jabber");

	if (!jabber) {
		return FALSE;
	}

	handle = purple_conversations_get_handle();
	ft_handle = purple_xfers_get_handle();

	/* XMPP stream signals */
	purple_signal_connect( jabber, "jabber-receiving-xmlnode", 
				plugin, PURPLE_CALLBACK(xmlnode_received_cb), NULL);
        purple_signal_connect( jabber, "jabber-sending-text", 
			        plugin, PURPLE_CALLBACK(xmlnode_sent_cb), NULL);

	/* File transfer signals */
	purple_signal_connect( ft_handle, "file-recv-start",
				plugin, PURPLE_CALLBACK(ft_recv_start_cb), NULL);
	purple_signal_connect( ft_handle, "file-recv-cancel",
				plugin, PURPLE_CALLBACK(ft_recv_cancel_cb), NULL);
	purple_signal_connect( ft_handle, "file-recv-complete",
				plugin, PURPLE_CALLBACK(ft_recv_complete_cb), NULL);

	purple_signal_connect( ft_handle, "file-send-start",
				plugin, PURPLE_CALLBACK(ft_send_start_cb), NULL);
	purple_signal_connect( ft_handle, "file-send-cancel",
				plugin, PURPLE_CALLBACK(ft_send_cancel_cb), NULL);
	purple_signal_connect( ft_handle, "file-send-complete",
				plugin, PURPLE_CALLBACK(ft_send_complete_cb), NULL);

	plugin_load_hook();
	
	return TRUE;
}

static gboolean
plugin_unload(PurplePlugin *plugin)
{
	PurplePlugin *jabber;
	PurplePlugin *handle;
	PurplePlugin *ft_handle;

	jabber = purple_find_prpl("prpl-jabber");

	if (!jabber) {
		return FALSE;
	}

	handle = purple_conversations_get_handle();
	ft_handle = purple_xfers_get_handle();

	/* XMPP stream signals */
	purple_signal_disconnect( jabber, "jabber-receiving-xmlnode", 
				plugin, PURPLE_CALLBACK(xmlnode_received_cb));
        purple_signal_disconnect( jabber, "jabber-sending-text", 
			        plugin, PURPLE_CALLBACK(xmlnode_sent_cb));

	/* File transfer signals */
	purple_signal_disconnect( ft_handle, "file-recv-start",
				plugin, PURPLE_CALLBACK(ft_recv_start_cb));
	purple_signal_disconnect( ft_handle, "file-recv-cancel",
				plugin, PURPLE_CALLBACK(ft_recv_cancel_cb));
	purple_signal_disconnect( ft_handle, "file-recv-complete",
				plugin, PURPLE_CALLBACK(ft_recv_complete_cb));

	purple_signal_disconnect( ft_handle, "file-send-start",
				plugin, PURPLE_CALLBACK(ft_send_start_cb));
	purple_signal_disconnect( ft_handle, "file-send-cancel",
				plugin, PURPLE_CALLBACK(ft_send_cancel_cb));
	purple_signal_disconnect( ft_handle, "file-send-complete",
				plugin, PURPLE_CALLBACK(ft_send_complete_cb));
	return TRUE;
}


static PurplePluginInfo info =
{
	PURPLE_PLUGIN_MAGIC,
	PURPLE_MAJOR_VERSION,
	PURPLE_MINOR_VERSION,
	PURPLE_PLUGIN_STANDARD,                           /**< type           */
	PIDGIN_PLUGIN_TYPE,                               /**< ui_requirement */
	0,                                                /**< flags          */
	NULL,                                             /**< dependencies   */
	PURPLE_PRIORITY_DEFAULT,                          /**< priority       */

	"pidbus",                                      /**< id             */
	"Pidgin D-Bus service",                            /**< name           */
	DISPLAY_VERSION,                                  /**< version        */
	                                                  
	"Start and connect inkboard from pidgin.",    /**  summary        */
	"This plugin is useful for online whiteboard shareing.",  /**  description    */
	"Mat <matlinuxer2@gmail.com>",                    /**< author         */
	"http://code.google.com/p/inkboardng/",		  /**< homepage       */

	plugin_load,                                      /**< load           */
	plugin_unload,                                    /**< unload         */
	NULL,                                             /**< destroy        */

	NULL,                                             /**< ui_info        */
	NULL,                                             /**< extra_info     */
	NULL,
	NULL,

	/* padding */
	NULL,
	NULL,
	NULL,
	NULL
};

static void
init_plugin(PurplePlugin *plugin)
{

}

PURPLE_INIT_PLUGIN( pinkboard, init_plugin, info)
